#ifndef __DRV_INA3221_H_
#define __DRV_INA3221_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "system.h"

typedef union
{
    struct
    {
        uint16_t rst : 1;
        uint16_t ch1_en : 1;
        uint16_t ch2_en : 1;
        uint16_t ch3_en : 1;
        uint16_t avg : 3;     // Averaging Mode 采样平均值数
        uint16_t vbus_ct : 3; // Bus-voltage conversion time 转换时间
        uint16_t vsh_ct : 3;
        uint16_t mode : 3;
    } ch;
    uint16_t cfg;
} _drv_ina_cfg_t;

/* export var */

enum
{
    INA_CFG_AVG_1 = 0, //[default]
    INA_CFG_AVG_4,
    INA_CFG_AVG_16,
    INA_CFG_AVG_64,
    INA_CFG_AVG_128,
    INA_CFG_AVG_256,
    INA_CFG_AVG_512,
    INA_CFG_AVG_1024,
};

enum
{
    INA_CFG_CT_140US = 0,
    INA_CFG_CT_204US,
    INA_CFG_CT_332US,
    INA_CFG_CT_588US,
    INA_CFG_CT_1P1MS, //[default]
    INA_CFG_CT_2P116MS,
    INA_CFG_CT_4P156MS,
    INA_CFG_CT_8P244MS,
};

enum
{
    INA_CFG_MODE_POWERDOWN = 0, // Power-down
    INA_CFG_MODE_SH_VOL_TRIG,   // Shunt voltage, signle-shot
    INA_CFG_MODE_BUS_VOL_TRIG,
    INA_CFG_MODE_SH_BUS_VOL_TRIG,
    INA_CFG_MODE_POWERDOWN2,
    INA_CFG_MODE_SH_VOL_CON, // Shunt voltage, continuous
    INA_CFG_MODE_BUS_VOL_CON,
    INA_CFG_MODE_SH_BUS_VOL_CON, //[default]
};


/* export func */

void drv_ina3221_init(void);

void drv_ina3221_set_config(_drv_ina_cfg_t cfg);

uint16_t drv_ina3221_get_shunt_vol(uint8_t ch);
uint16_t drv_ina3221_get_bus_vol(uint8_t ch);
void drv_ina3221_get_value(uint8_t ch, int16_t *vol, int16_t *ele);

uint16_t drv_ina3221_get_man_id(void);
uint16_t drv_ina3221_get_die_id(void);

#ifdef __cplusplus
}
#endif

#endif // __DRV_INA3221_H_
